import { defineStore } from 'pinia'
import cacheUtils from '@/utils/cacheUtils'
import { themeModeEnum, keyThemePrefix } from '@/utils/themeUtils'
import { useIpcRenderer } from '@vueuse/electron'
const ipcRenderer = useIpcRenderer()
const keyTitlePrefix = 'title'

/**应用相关状态管理 */
export const useApp = defineStore('app', {
  state() {
    return {
      /*  lang: cacheUtils.get("lang") || "zhCn", // app的语言 */
      theme: cacheUtils.get(keyThemePrefix + 'mode') || themeModeEnum.light, // app的主题
      title: cacheUtils.get(keyTitlePrefix) || '晓安智能助手' // 获取初始标题值
    }
  },
  actions: {
    //TODO:
    getSystemTitle() {
      // 获取系统标题及颜色模式
      // this.title = res.data.title
    },
    // 更新系统标题
    updateSystemTitle(title) {
      this.title = title
      cacheUtils.set(keyTitlePrefix, title)
      ipcRenderer.invoke('system-title:change', title)
      document.title = title
    }
  }
})
